package com.woniuxy.joylife.manager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.joylife.manager.dao.DepartmentDao;
import com.woniuxy.joylife.manager.entity.DepartmentEntity;
import com.woniuxy.joylife.manager.service.DepartmentService;
import com.woniuxy.joylife.manager.utils.PageUtils;
import com.woniuxy.joylife.manager.utils.Query;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("departmentService")
public class DepartmentServiceImpl extends ServiceImpl<DepartmentDao, DepartmentEntity> implements DepartmentService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<DepartmentEntity> page = this.page(
                new Query<DepartmentEntity>().getPage(params),
                new QueryWrapper<DepartmentEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public Boolean saveDepartmentEntity(DepartmentEntity department) {
        QueryWrapper<DepartmentEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name",department.getName());
        DepartmentEntity departmentEntity = baseMapper.selectOne(queryWrapper);
        if(departmentEntity==null){
            baseMapper.insert(department);
            return true;
        }else {
            return false;
        }
    }

}